<?php
class couponAction extends BaseAction{
	
	public function _initialize() {
		parent::_initialize();
	}

	/**
	 * 查看礼券
	 */
	public function index(){
		$this->display();
	}
	
	/**
	 * 通过券码、手机号、验证码查看对应的券信息。
	 */
	public function search(){
		
		$passcode = $_POST['passcode'];
		$mobile = $_POST['mobile'];
		if(empty($passcode)){echo "passcode";exit;}
		if(!isValidMobile($mobile)){echo "mobile";exit;}
		//检查验证码
		if(empty($_POST['verify']) || md5($_POST['verify'])!=$_SESSION['verify']){echo "verify";exit;}
		$_SESSION['verify']=time();//查询成功后，重新设置验证码。
		
		$coupon = service('Coupon')->getByPasscode($passcode);
		if(empty($coupon)||$coupon['receiver_mobile']!=$mobile){
			echo "coupon";exit;
		}
		
		$this->assign('coupon', $coupon);
		$this->display('show');
	}
}
